package com.zhen.generator;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import cn.org.rapid_framework.generator.util.GLogger;

/**
 * 数据库信息获得操作类。
 * 
 * @author Luffy
 *
 */
public class DatabaseInfoOp {

    Connection conn = null;

    private String classDriver;

    private String url;

    private String username;

    private String password;

    public DatabaseInfoOp(String classDriver, String url, String username,
            String password) {
        super();
        this.classDriver = classDriver;
        this.url = url;
        this.username = username;
        this.password = password;
    }

    public Connection getConnectionByJDBC() {
        try {
            // 装载驱动包类
            Class.forName(classDriver);
            // 加载驱动
            conn = DriverManager.getConnection(url, username, password);
        }
        catch (ClassNotFoundException e) {
            GLogger.error("装载驱动包出现异常!请查正！", e);
        }
        catch (SQLException e) {
            GLogger.error("链接数据库发生异常!", e);
        }
        return conn;
    }

}
